#include "BreakPointFile.h"
#include <cassert>
#include "Util.h"

BreakPointFile::BreakPointFile(const std::string & fileName) 
: _fileName(fileName) {
  if(!util::File::exists(fileName)){
    util::File::create(fileName);
  }
}

BreakPointFile::~BreakPointFile(){
}

int BreakPointFile::load(){
  int no = 0;
  int ret =util::File::readAsBinary(_fileName, &no); 
  return (ret > 0) ? no : 0; //NOTE: read failed -> return 0;
}

int BreakPointFile::save(int no){
  int ret = util::File::writeAndFlushAsBinary(_fileName, no);
  return ret > 0 ? 0 : -1;
}

void test_breakpoint_file(){
	const char * fileName = "breakpoint.refactoring.file";
	if(util::File::exists(fileName)) {
		assert(util::File::remove(fileName));
	}

	BreakPointFile breakpointFile(fileName);
	assert(util::File::exists(fileName));
	assert(0 == breakpointFile.load());

	assert(0 == breakpointFile.save(1));

}
